<?php

namespace App\Admin\Renderable;

use App\Models\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserTable extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new User(), function (Grid $grid) {

            $region_code = $this->payload['region_code'];
            if ($region_code) {
                $grid->model()->where('region_code', $region_code);
            }

            $grid->model()->where('role', 0); // 普通用户

            $grid->column('id', 'ID')->sortable();
            $grid->column('user_name', '用户名');
            $grid->column('real_name', '真实姓名');
            $grid->column('phone_num', '电话');
            $grid->column('created_at', '注册时间');

            $grid->quickSearch(['id', 'user_name', 'real_name', 'phone_num']);

            $grid->paginate(10);
            $grid->disableActions();
        });

    }
}